<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\widgets\ActiveForm;

//use mdm\admin\components\AccessControl;
/* @var $this yii\web\View */
/* @var $searchModel ua_backend\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '后台用户管理';

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="box">
    <div class="box-header with-border">


        <?php
            if(Yii::$app->user->can('后台管理') || Yii::$app->user->can('admin')){
                echo Html::a('<i class="fa fa-plus-circle"> </i> '.Yii::t('app', 'Create').'', ['create'], ['class' => 'btn btn-success btn-sm']);
            }else{
                echo '<a class="btn btn-sm"></a>';
            }
        ?>

        <div class="box-tools">
            <?php $form = ActiveForm::begin([
                            'action' => ['list'],
                            'method' => 'get',
                            'id' => 'search-form',
                            'options' => ['class' => 'form-horizontal'],
                        ]); ?>
                            <div class='input-group input-group-sm' style='width: 300px;margin-top:5px;'>
                            <?= $form->field($searchModel, 'skey',[
                                  'options'=>['class'=>'input-group input-group-sm','style'=>'width: 300px;'],
                                  'inputOptions' => ['placeholder' => Yii::t('app', 'Search Keyword'),'class' => 'form-control pull-right'],
                                    ])->label(false); ?>
                             <div class="input-group-btn">
                                <button class="btn btn-default" type="submit">
                                <i class="fa fa-search"></i>
                                </button>
                             </div>
                             </div>

            <?php ActiveForm::end(); ?>
        </div>
    </div>

<?php Pjax::begin(); ?>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'layout' => '<div class="box-body">{items}</div>
                         <div class="box-footer">
                            {summary}
                            <div class="_pager">{pager}</div>
                         </div>',
        //'filterModel' => $searchModel,
        //'summary' => '显示{begin}-{end},一共{count}条记录',
//
//        'summary'=> Yii::t('app', 'Showing {begin}-{end} of {totalCount} items.'),
//
//        'options' => [
//            'class' => 'box-body',
//        ],

//        'tableOptions' => ['class' => 'table table-hover'],

        'columns' => [
            'id' => [
                    'attribute' => 'id',
                    'enableSorting' => false,
                ],

//                [
//                    'attribute' => 'id',
//                    'label' => '二维码',
//                    'enableSorting' => false,
//                    'format' => 'raw',
//                    'value'=> function($model){
//                        $html = '<a href="#" onclick="openQrcode(\''.$model->code.'\');return;"><i class="glyphicon glyphicon-qrcode fs-18"></i></a>';
//                        return $html;
//                    },
//                ],

                'username' => [
                    'attribute' => 'username',
                    'label' => Yii::t('app', 'Username'),
                    //'enableSorting' => false,
                ],

//                'city' => [
//                    'attribute' => 'city',
//                    'label' => '城市',
//                    //'enableSorting' => false,
//                ],
//
//                'code' => [
//                    'attribute' => 'code',
//                    'label' => '登录码',
//                    //'enableSorting' => false,
//                ],
//
//                'store_name' => [
//                    'attribute' => 'store_name',
//                    'label' => '经销商名称',
//                    //'enableSorting' => false,
//                ],

//                 'store_address' => [
//                     'attribute' => 'store_address',
//                     'label' => '地址',
//                     //'enableSorting' => false,
//                 ],
//
//                 'store_contact_person' => [
//                     'attribute' => 'store_contact_person',
//                     'label' => '联系人',
//                     //'enableSorting' => false,
//                 ],
//
//                'store_contact_phone' => [
//                    'attribute' => 'store_contact_phone',
//                    'label' => '联系电话',
//                    //'enableSorting' => false,
//                ],

                 [
                    'attribute' => 'role',
                     'label' => Yii::t('app', 'Role'),
                     'format' => 'html',
                    'value'=> function($model){
                        return  $model->role==20?'<span class="label label-success">管理员</span>':'<span class="label label-warning">普通用户</span>';
                    },
                    'enableSorting' => false,
                ],

                [
                    'attribute' => 'created_at',
                    'label' => Yii::t('app', 'Created at'),
                    'format' => ['date', 'php:Y-m-d h:i:s'],
                    'enableSorting' => false,
                ],

                [
                    'class' => 'yii\grid\ActionColumn',
                        'template' => $template
                ],
        ],
    ]); ?>
<?php Pjax::end(); ?>
</div>

<script>
    function openQrcode(code) {
        var url = 'qrcode?dealer_code='+code
        window.open(url)
    }
</script>
